﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.ValentineUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;

    public class ValentineCardViewDialog extends GenericDialog {

        public static var assetDict:Dictionary;

        public var m_cardData:Array;
        public var m_senderID:Admirer;
        protected var m_secondWindow:JWindow;
        protected var m_secondPanel:JPanel;
        protected var m_firstHolder:Sprite;
        protected var m_secondHolder:Sprite;

        public function ValentineCardViewDialog(_arg1:Array, _arg2:Admirer){
            this.m_cardData = _arg1;
            this.m_senderID = _arg2;
            m_lightbox = true;
            super("", "", GenericDialogView.TYPE_CUSTOM_OK, this.shareThanks, "ValUIView", "", true, 0, "", null, ZLoc.t("Dialogs", "ValUIView_btn"));
        }
        override protected function loadAssets():void{
            Global.delayedAssets.get(DelayedAssetLoader.VALENTINES_ASSETS, makeAssets);
        }
        override protected function createAssetDict():Dictionary{
            assetDict = new Dictionary();
            assetDict["cardData"] = this.m_cardData;
            assetDict["admirer"] = this.m_senderID;
            assetDict["market_next_down"] = (new m_comObject.market_next_down() as DisplayObject);
            assetDict["market_next_over"] = (new m_comObject.market_next_over() as DisplayObject);
            assetDict["market_next_up"] = (new m_comObject.market_next_up() as DisplayObject);
            assetDict["market_prev_down"] = (new m_comObject.market_prev_down() as DisplayObject);
            assetDict["market_prev_over"] = (new m_comObject.market_prev_over() as DisplayObject);
            assetDict["market_prev_up"] = (new m_comObject.market_prev_up() as DisplayObject);
            assetDict["noportrait"] = m_comObject.valentinesDay_admirerCard_blank;
            assetDict["valentinesDay_achievementStamp"] = m_comObject.valentinesDay_achievementStamp;
            assetDict["dialog_bg"] = (new m_comObject.valentinesDay_viewerBG() as DisplayObject);
            return (assetDict);
        }
        protected function shareThanks(_arg1:GenericPopupEvent):void{
            if (_arg1.button == GenericDialogView.YES){
                if (this.m_senderID.uid != Player.FAKE_USER_ID_STRING){
                    Global.world.viralMgr.vdaySendCardThankYou(this.m_senderID.uid);
                };
            };
            StatsManager.count(StatsCounterType.CARDMAKER, StatsKingdomType.VDAY_2011, StatsPhylumType.CARDVIEWER, "share");
        }
        override protected function onShow():void{
            if (m_shown == false){
                if (m_modal){
                    InputManager.disableInput();
                    Global.ui.mouseEnabled = false;
                    Global.ui.mouseChildren = false;
                };
                if (m_lightbox){
                    Global.ui.displayLightbox(true, UI.MASK_ALL_UI);
                };
                if (useSystemCursor()){
                    m_cursorId = UI.setCursor(null);
                };
                this.mouseEnabled = (this.mouseChildren = true);
                m_shown = true;
                Global.stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreen);
            } else {
                m_showOnLoad = true;
            };
            if (!Global.guide.isActive()){
                Sounds.play("dialogSpawn");
            };
        }
        protected function createSecondPanel(_arg1:int=0):JPanel{
            var jp:* = null;
            var bgAsset:* = null;
            var icon:* = null;
            var ind:int = _arg1;
            jp = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER);
            bgAsset = (new (assetDict["valentinesDay_achievementStamp"])() as DisplayObject);
            var curCard:* = this.m_cardData[ind];
            var icons:* = curCard.findMatchingAchievementIcons();
            if (icons.length == 0){
                return (jp);
            };
            var iconUrl:* = icons[(icons.length - 1)];
            icon = LoadingManager.load(Global.getAssetURL(iconUrl), function (_arg1:Event):void{
                jp.removeAll();
                var _local2:* = new AssetPane(icon.content);
                ASwingHelper.setEasyBorder(_local2, ((bgAsset.height - icon.content.height) / 2));
                jp.append(_local2);
                ASwingHelper.prepare(jp.parent);
            });
            ASwingHelper.setSizedBackground(jp, bgAsset);
            return (jp);
        }
        protected function changeAchievement(_arg1:GenericObjectEvent):void{
            this.m_secondWindow.hide();
            this.m_secondWindow.removeAll();
            this.m_secondPanel = this.createSecondPanel(_arg1.obj.index);
            this.m_secondWindow.setContentPane(this.m_secondPanel);
            ASwingHelper.prepare(this.m_secondWindow);
            this.m_secondWindow.show();
        }
        override protected function init():void{
            m_holder = new Sprite();
            this.addChild(m_holder);
            var _local1:Sprite = new Sprite();
            m_holder.addChild(_local1);
            m_jwindow = new JWindow(_local1);
            m_content = m_holder;
            m_content.addEventListener(GenericObjectEvent.REFRESH_ACHIEVEMENT, this.changeAchievement, false, 0, true);
            m_content.addEventListener(GenericPopupEvent.SELECTED, processSelection, false, 0, true);
            m_content.addEventListener(UIEvent.REFRESH_DIALOG, onRefreshDialog, false, 0, true);
            m_content.addEventListener("close", closeMe, false, 0, true);
        }
        override protected function finalizeAndShow():void{
            ASwingHelper.prepare(m_jpanel);
            m_jwindow.setContentPane(m_jpanel);
            ASwingHelper.prepare(m_jwindow);
            if (((((m_assetBG) && ((m_title == "")))) && ((m_assetBG.height > m_jwindow.getHeight())))){
                m_jwindow.setPreferredHeight((m_assetBG.height + 1));
                ASwingHelper.prepare(m_jwindow);
            };
            var _local1:int = m_jwindow.getWidth();
            var _local2:int = m_jwindow.getHeight();
            m_jwindow.show();
            this.m_secondHolder = new Sprite();
            m_holder.addChild(this.m_secondHolder);
            this.m_secondHolder.x = 425;
            this.m_secondHolder.y = 320;
            this.m_secondPanel = this.createSecondPanel((assetDict["cardData"].length - 1));
            this.m_secondWindow = new JWindow(this.m_secondHolder);
            ASwingHelper.prepare(this.m_secondPanel);
            this.m_secondWindow.setContentPane(this.m_secondPanel);
            ASwingHelper.prepare(this.m_secondWindow);
            this.m_secondWindow.show();
            m_holder.width = _local1;
            m_holder.height = _local2;
            onDialogInitialized();
        }
        override protected function createDialogView(_arg1:Dictionary):GenericDialogView{
            return (new ValentineCardViewDialogView(_arg1, m_message, m_title, m_type, m_callback, "", 0, "", null, ZLoc.t("Dialogs", "ValUIView_btn")));
        }

    }
}//package Display.ValentineUI 
